home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xa / QlickerBtn.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  4.6 KB  |  169 lines

  1. package com.extensibility.xa;
  2.  
  3. import com.extensibility.rock.RBevelBorder;
  4. import java.awt.AWTEventMulticaster;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Dimension;
  8. import java.awt.Graphics;
  9. import java.awt.Insets;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import javax.swing.BorderFactory;
  13. import javax.swing.Icon;
  14. import javax.swing.JComponent;
  15. import javax.swing.border.Border;
  16. import javax.swing.border.CompoundBorder;
  17. import javax.swing.border.EmptyBorder;
  18.  
  19. public class QlickerBtn extends JComponent {
  20.    static final int H_TEXTINSET = 0;
  21.    static final int V_TEXTINSET = 1;
  22.    static final int ICON_GAP = 3;
  23.    Border normalBorder;
  24.    Border depressedBorder;
  25.    Border disabledBorder;
  26.    String name;
  27.    Icon icon;
  28.    int nameWidth;
  29.    boolean transparent;
  30.    ActionListener actionListener;
  31.    ML mouseListener;
  32.    boolean cbState;
  33.    boolean wasPopupTrigger;
  34.  
  35.    public QlickerBtn() {
  36.       this("");
  37.       this.transparent = true;
  38.    }
  39.  
  40.    public QlickerBtn(String var1) {
  41.       this.transparent = false;
  42.       this.actionListener = null;
  43.       this.mouseListener = new ML(this);
  44.       this.cbState = false;
  45.       this.name = var1;
  46.       this.normalBorder = this.createNormalBorder();
  47.       this.depressedBorder = this.createDepressedBorder();
  48.       this.disabledBorder = this.createDisabledBorder();
  49.       ((JComponent)this).setBorder(this.normalBorder);
  50.       ((Component)this).addMouseListener(this.mouseListener);
  51.    }
  52.  
  53.    public QlickerBtn(String var1, Icon var2) {
  54.       this(var1);
  55.       this.icon = var2;
  56.    }
  57.  
  58.    public QlickerBtn(Icon var1) {
  59.       this("");
  60.       this.icon = var1;
  61.    }
  62.  
  63.    protected Border createNormalBorder() {
  64.       return new CompoundBorder(new RBevelBorder(0), new EmptyBorder(1, 2, 1, 2));
  65.    }
  66.  
  67.    protected Border createDepressedBorder() {
  68.       return new CompoundBorder(new RBevelBorder(1), new EmptyBorder(1, 2, 1, 2));
  69.    }
  70.  
  71.    protected Border createDisabledBorder() {
  72.       return BorderFactory.createEmptyBorder();
  73.    }
  74.  
  75.    public Dimension getPreferredSize() {
  76.       if (this.transparent) {
  77.          return ((Component)this).getSize();
  78.       } else {
  79.          Insets var1 = this.normalBorder.getBorderInsets(this);
  80.          return new Dimension(this.getNameWidth() + 0 + var1.left + var1.right, ((Component)this).getFontMetrics(((Component)this).getFont()).getAscent() + 2 + var1.bottom + var1.top);
  81.       }
  82.    }
  83.  
  84.    public void addActionListener(ActionListener var1) {
  85.       this.actionListener = AWTEventMulticaster.add(this.actionListener, var1);
  86.    }
  87.  
  88.    public void removeActionListener(ActionListener var1) {
  89.       this.actionListener = AWTEventMulticaster.remove(this.actionListener, var1);
  90.    }
  91.  
  92.    public void processEvent(ActionEvent var1) {
  93.       if (this.actionListener != null) {
  94.          this.actionListener.actionPerformed(var1);
  95.       }
  96.  
  97.    }
  98.  
  99.    protected int getNameWidth() {
  100.       if (this.nameWidth == 0) {
  101.          this.nameWidth = ((Component)this).getFontMetrics(((Component)this).getFont()).stringWidth(this.name);
  102.          if (this.icon != null) {
  103.             this.nameWidth += this.icon.getIconWidth() + 3;
  104.          }
  105.       }
  106.  
  107.       return this.nameWidth;
  108.    }
  109.  
  110.    protected int desiredWidth() {
  111.       int var1 = this.getNameWidth() + 0 + 1;
  112.       return var1;
  113.    }
  114.  
  115.    protected void setIcon(Icon var1) {
  116.       this.icon = var1;
  117.       ((Component)this).repaint();
  118.    }
  119.  
  120.    public void setPressed(boolean var1) {
  121.       if (((Component)this).isEnabled()) {
  122.          if (this.cbState != var1) {
  123.             this.cbState = var1;
  124.             Border var2 = this.normalBorder;
  125.             this.normalBorder = this.depressedBorder;
  126.             this.depressedBorder = var2;
  127.             ((JComponent)this).setBorder(this.normalBorder);
  128.             ((Component)this).repaint();
  129.          }
  130.       }
  131.    }
  132.  
  133.    public void setEnabled(boolean var1) {
  134.       if (var1 != ((Component)this).isEnabled()) {
  135.          if (var1) {
  136.             ((Component)this).addMouseListener(this.mouseListener);
  137.          } else {
  138.             ((Component)this).removeMouseListener(this.mouseListener);
  139.          }
  140.  
  141.          ((JComponent)this).setBorder(var1 ? this.normalBorder : this.disabledBorder);
  142.          super.setEnabled(var1);
  143.          ((Component)this).repaint();
  144.       }
  145.    }
  146.  
  147.    public boolean isPressed() {
  148.       return this.cbState;
  149.    }
  150.  
  151.    public void paintComponent(Graphics var1) {
  152.       super.paintComponent(var1);
  153.       if (!this.transparent) {
  154.          var1.setColor(((Component)this).getBackground());
  155.          var1.fillRect(0, 0, ((JComponent)this).getWidth(), ((JComponent)this).getHeight());
  156.          int var2 = var1.getFontMetrics().getAscent();
  157.          var1.setColor(Color.black);
  158.          Insets var3 = this.normalBorder.getBorderInsets(this);
  159.          int var4 = var3.left + 0;
  160.          int var5 = var3.top + 1 + var2;
  161.          var1.drawString(this.name, var4, var5);
  162.          if (this.icon != null) {
  163.             this.icon.paintIcon(this, var1, ((JComponent)this).getWidth() - 0 - var3.right - this.icon.getIconWidth(), var5 - this.icon.getIconHeight());
  164.          }
  165.  
  166.       }
  167.    }
  168. }
  169.